package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * Title:
 * Author: fusu
 * DateTime:  2023/3/24
 * Description:
 **/
@Api(tags = "物资模块-物资来源接口")
@RestController
@RequestMapping("/business/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    @ApiOperation(value = "物资来源分类列表展示+查询")
    @GetMapping("/findSupplierList")
    public ResponseBean findSupplierList(@RequestParam("pageNum") Integer pageNum,
                                         @RequestParam("pageSize") Integer pageSize,
                                         Supplier supplier) {
        PageVO suppliers = supplierService.findSupplierList(pageNum, pageSize, supplier);
        return ResponseBean.success(suppliers);
    }

    @ApiOperation(value = "添加物资来源")
    @PostMapping("/add")
    public ResponseBean addSupplier(@RequestBody Supplier supplier) {
        supplierService.addSupplier(supplier);
        return ResponseBean.success();
    }

    @ApiOperation(value = "根据id查询物资来源")
    @GetMapping("/edit/{supplierId}")
    public ResponseBean getBySupplierId(@PathVariable("supplierId") Long supplierId) {
        Supplier supplier = supplierService.getBySupplierId(supplierId);
        return ResponseBean.success(supplier);
    }

    @ApiOperation(value = "根据id更新")
    @PutMapping("/update/{supplierId}")
    public ResponseBean updateBySupplierId(@PathVariable("supplierId") Long supplierId,
                                           @RequestBody Supplier supplier) {
        supplier.setId(supplierId);
        supplier.setModifiedTime(new Date());
        supplierService.updateBySupplierId(supplier);
        return ResponseBean.success();
    }

    @ApiOperation(value = "根据id删除")
    @DeleteMapping("/delete/{supplierId}")
    public ResponseBean deleteBySupplierId(@PathVariable("supplierId") Long supplierId) {
        supplierService.deleteBySupplierId(supplierId);
        return ResponseBean.success();
    }

    @ApiOperation(value = "获取所有")
    @GetMapping("/findAll")
    public ResponseBean findAll() {
        List<Supplier> suppliers = supplierService.findAll();
        return ResponseBean.success(suppliers);
    }
}
